# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gptfdisk
pkgver=1.0.9
pkgrel=4
pkgdesc="Text-mode partitioning tool that works on Globally Unique Identifier (GUID) Partition Table (GPT) disks"
arch="all"
url="https://www.rodsbooks.com/gdisk"
license="GPL-2.0-or-later"
makedepends="ncurses-dev e2fsprogs-dev popt-dev linux-headers"
subpackages="$pkgname-doc sgdisk"
source="https://downloads.sourceforge.net/project/gptfdisk/gptfdisk/$pkgver/gptfdisk-$pkgver.tar.gz
	fix-wrong-include.patch
	0001-Fix-failure-crash-of-sgdisk-when-compiled-with-lates.patch
	0002-Updated-guid.cc-to-deal-with-minor-change-in-libuuid.patch
	0003-Fix-NULL-dereference-when-duplicating-string-argumen.patch
	fix-musl.patch
	"
# secfixes:
#   1.0.6-r0:
#     - CVE-2021-0308
#     - CVE-2020-0256

build() {
	make CXX="${CXX:-g++}" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
}

package() {
	mkdir -p "$pkgdir"/usr/bin "$pkgdir"/usr/share/man/man8
	local i; for i in gdisk cgdisk sgdisk fixparts; do
		install $i "$pkgdir"/usr/bin/
		install $i.8 "$pkgdir"/usr/share/man/man8/
	done
}

check() {
	sh "$builddir"/gdisk_test.sh
}

sgdisk() {
	pkgdesc="Command-line GUID partition table (GPT) manipulator"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/sgdisk "$subpkgdir"/usr/bin/
}

sha512sums="
c2489ac7e196cb53b9fdb18d0e421571eca43c366de8922c5c7f550aadf192558e7af69b181c30747d6cf607c1670126223465eaa5e231cc589402d94a4e97a2  gptfdisk-1.0.9.tar.gz
9b64c0e565137b4d4275bd6e8b050f98a73ff5593093b54d43736e6aabd24abf6e35d88ea27be17c5fee70aada4ad05a70fe5af3523212aad114f05aaf82356f  fix-wrong-include.patch
ebd680343cd7f559503156984f056f4b49cc3581c8c7f623c66c10bb79e1dd7ee9e217cbd0479ebe3b7bce3b34b85428bc3525aa354b76789e9bcbaf1000a889  0001-Fix-failure-crash-of-sgdisk-when-compiled-with-lates.patch
fd2747714f854a2abaa5cbd113a9bf9eea3d8ee6c46e47dbe3246c9d3bebb621a2a7bc623827f6f44870133eb09b5b991ea73d03755fa0e2b9d73c5cea821f33  0002-Updated-guid.cc-to-deal-with-minor-change-in-libuuid.patch
f1d3b1d43490665dbe2b024027b12803ec73698dc232335fd87813ffb940202032c8f47c3410190a00d16382a2ceb35effc1f825ca87f6a0cd3dad564bb751af  0003-Fix-NULL-dereference-when-duplicating-string-argumen.patch
c85306ad9902d4c4f685c8fa5f6f4e1976d3036a4fc747cbc68403fa811a177a0d6ce29575c4d2dc03ccf9bcc44167dd5830eb8f548d9d55d2b6579ed1b4ffab  fix-musl.patch
"
